package com.platform.data.handle.converter;

import com.platform.data.handle.converter.impl.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

/**
 * 数据类型转换
 *
 * @author zhuweijun
 * @version 1.0.0
 * @since 2025/5/13 13:13
 */
public class DataTypeConverterHandler {
    private static final Logger log = LoggerFactory.getLogger(DataTypeConverterHandler.class);

    public enum TypeEnum {
        STRING("String", new StringTypeProcessHandler()),
        INTEGER("Integer", new IntegerTypeProcessHandler()),
        BIG_DECIMAL("BigDecimal", new BigDecimalTypeProcessHandler()),
        ARRAY("List", new ArrayObjectTypeProcessHandler()),
        ARRAY_STRING("List_String", new ArrayStringTypeProcessHandler()),
        ARRAY_INTEGER("List_Integer", new ArrayIntegerTypeProcessHandler()),
        ENUM_STRING("Enum_String", new EnumStringTypeProcessHandler()),
        ENUM_INTEGER("Enum_Integer", new EnumIntegerTypeProcessHandler()),
        DATE_STRING("Date_String", new DateTypeProcessHandler()),
        ;

        /**
         * 数据类型
         */
        public final String processType;

        /**
         * 处理类型
         */
        public final AbstractDataTypeProcessHandler processHandler;

        TypeEnum(String processType, AbstractDataTypeProcessHandler processHandler) {
            this.processType = processType;
            this.processHandler = processHandler;
        }

        public AbstractDataTypeProcessHandler getProcessHandler() {
            return processHandler;
        }
    }

    /**
     * 获取属性数据类型处理类
     *
     * @param processType processType
     * @return {@link TypeEnum}
     */
    public TypeEnum getDataProcessHandler(String processType) {
        for (TypeEnum anEnum : TypeEnum.values()) {
            if(Objects.equals(anEnum.processType, processType)){
                return anEnum;
            }
        }
        return null;
    }
}
